package com.gaara.test;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.Rect;

public class MyButton {

	public Bitmap skin;
	public Bitmap skinDown;
	public Boolean isDown;
	public Point postion;
	
	public MyButton(Bitmap skin,Bitmap skinDown,int x,int y) {
		this.skin = skin;
		this.skinDown = skinDown;
		this.postion = new Point(x, y);
		isDown = false;
	}

	/** 传入触摸点 **/
	public Boolean onTouch(Point point) {
		Rect rect = new Rect(postion.x, postion.y, postion.x+this.skin.getWidth(), postion.y+this.skin.getHeight());
		if(rect.contains(point.x, point.y)){
			isDown = true;
			this.onClick();
		}
		else {
			isDown = false;
		}
		return isDown;
	}
	
	public void onClick(){
		
	}
	
	public void draw(Canvas canvas) {
		Bitmap showBitamp;
		if(isDown == true){
			showBitamp = skin;
		}
		else {
			showBitamp = skinDown;
		}
		
		canvas.drawBitmap(showBitamp, postion.x, postion.y, new Paint());
	}
	
}
